<?php


namespace App\servers;


class DxbSmsServer implements SendsmsInterface
{
    /**
     * 短信宝发送验证码
     * @param $phone
     * @param bool $debug
     * @return bool
     */
    public function send($phone,$debug = false)
    {
        $code = rand(1111,9999);
        $content='欢迎回来:'.$code;//要发送的短信内容
//        if($debug){
//            $resdis = RedisServices::getInstance()->getRedis();
//            if($resdis->get($phone)) abort(40001,'请不要频繁发送');
//            $resdis->set($phone,$code,60);
//            return true;
//        }
        $statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );
        $smsapi = "http://api.smsbao.com/";
        $user = config('code.duanxb.username'); //短信平台帐号
        $pass = config('code.duanxb.password'); //短信平台密码
//        $phone = "*****";//要发送短信的手机号码
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl) ;
        var_dump($statusStr[$result]);
        if($result != 0 ) abort(40001,$statusStr[$result]);
        return true;
    }

    //测试短信
    public static function sendCeshi($phone,$code)
    {
        $content='验证码是:'.$code;//要发送的短信内容
        $statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );
        $smsapi = "http://api.smsbao.com/";
        $user = 'Lzh20030726'; //短信平台帐号
        $pass = md5('L13084229872'); //短信平台密码
//        $phone = "*****";//要发送短信的手机号码
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl) ;
        if($result != 0 && $result != 41) abort(40001,$statusStr[$result]);
        return true;
    }
}
